﻿Imports System.Windows.Forms
Imports System.Text

Public Class frmUnknownFormat

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub cmbSubFormat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSubFormat.SelectedIndexChanged
        Select Case cmbSubFormat.Text
            Case "SubRip (SRT)"
                frmMain.mySubtitles.setSubFormat("SubRip")
        End Select

        ReloadSub()
    End Sub

    Private Sub cmbEncoding_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbEncoding.SelectedIndexChanged
        Select Case cmbEncoding.Text
            Case "ANSI"
                frmMain.mySubtitles.setSubEncoding(Encoding.Default)
            Case "UTF-8"
                frmMain.mySubtitles.setSubEncoding(Encoding.UTF8)
            Case "Unicode"
                frmMain.mySubtitles.setSubEncoding(Encoding.Unicode)
            Case "Unicode Big Endian"
                frmMain.mySubtitles.setSubEncoding(Encoding.BigEndianUnicode)
        End Select

        ReloadSub()
    End Sub

    Private Sub ReloadSub()
        Dim testSubtitle As New Subtitles.SubtitleType
        Dim failed As Boolean = False

        Select Case frmMain.mySubtitles.getSubFormat
            Case "SubRip"
                testSubtitle = frmMain.mySubtitles.miniLoadSRTSubRip
                If Not testSubtitle.ID = -1 Then
                    lblIndex.Text = testSubtitle.ID
                    lblShow.Text = testSubtitle.showTime
                    lblHide.Text = testSubtitle.hideTime
                    lblText.Text = testSubtitle.text
                    btnOK.Enabled = True
                Else
                    failed = True
                End If
        End Select

        If failed Then
            lblIndex.Text = ""
            lblShow.Text = ""
            lblHide.Text = ""
            lblText.Text = loadStringFromLangFile("noSubtitlesWithCurrentSettings")
            btnOK.Enabled = False
        End If
    End Sub

    Private Sub frmUnknownFormat_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Select Case frmMain.mySubtitles.getSubFormat
            Case "SubRip"
                cmbSubFormat.SelectedIndex = 0
            Case Else
                cmbSubFormat.SelectedIndex = 0
        End Select
        cmbEncoding.SelectedIndex = 0
    End Sub

    Public Sub LoadLangStrings()
        lblExplanation.Text = loadStringFromLangFile("unknownFormatExplanation")
        lblEncoding.Text = loadStringFromLangFile("encoding")
        lblHideLabel.Text = loadStringFromLangFile("hideTableHeader")
        lblIndexLabel.Text = loadStringFromLangFile("subtitleEntryWord")
        lblShowLabel.Text = loadStringFromLangFile("showTableHeader")
        lblSubFormat.Text = loadStringFromLangFile("subtitleFormat")
        lblTextLabel.Text = loadStringFromLangFile("subtitleTableHeader")
        grpPreview.Text = loadStringFromLangFile("previewWord")
    End Sub
End Class
